package com.example.yiqingwaichu;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class ZtActivity1 extends AppCompatActivity {

    private TextView tv_mz1, tv_mz2, tv_mz3, tv_mz4, tv_xueh, tv_sj, tv_sj2, tv_sj1,tv_fcyy;
    private TextView tv_lxsj, tv_fxsj, tv_fdysj, tv_fdy, tv_zhuanye, tv_banji, tv_cxlx, tv_lxfas, tv_xb, tv_lxfs;
    private SimpleDateFormat rq = new SimpleDateFormat("yyyy-MM-dd");
    private Random random = new Random();
    private int sj222 = random.nextInt(60);
    private int sj23 = random.nextInt(60);
    private String sj;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        
        setContentView(R.layout.activity_main2);


        tv_mz1 = findViewById(R.id.tv_mz1);
        tv_mz2 = findViewById(R.id.tv_mz2);
        tv_mz3 = findViewById(R.id.tv_mz3);
        tv_mz4 = findViewById(R.id.tv_mz4);
        tv_xueh = findViewById(R.id.tv_xh1);
        tv_sj = findViewById(R.id.tv_sj);
        tv_sj2 = findViewById(R.id.tv_sj2);
        tv_sj1 = findViewById(R.id.tv_sj1);
        tv_lxsj = findViewById(R.id.tv_lxsj);
        tv_fxsj = findViewById(R.id.tv_fxsj);
        tv_fdysj = findViewById(R.id.tv_fdysj);
        tv_fdy = findViewById(R.id.tv_fdy);
        tv_zhuanye = findViewById(R.id.tv_zhuanye);
        tv_banji = findViewById(R.id.tv_banji);
        tv_cxlx = findViewById(R.id.tv_cxlx);
        tv_lxfas = findViewById(R.id.tv_lxfas);
        tv_xb =findViewById(R.id.tv_xb);
        tv_fcyy = findViewById(R.id.tv_fcyy);



        tv_lxsj.setText(rq.format(new Date()) + " 10:00");

        getqyt();





        tv_lxsj.setOnClickListener(v -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(ZtActivity1.this);
            builder.setTitle("请输入离校时间");
            final EditText et = new EditText(ZtActivity1.this);
            et.setSingleLine();
            et.setText(rq.format(new Date()) + " 10:00");
            builder.setView(et);
            builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String sa = et.getText().toString().trim();
                    tv_lxsj.setText(sa+"");
                }

            });
            builder.show();
            Toast.makeText(this,"修改成功",Toast.LENGTH_SHORT).show();



        });

        tv_fcyy.setOnClickListener(v -> {

            AlertDialog.Builder builder = new AlertDialog.Builder(ZtActivity1.this);
            builder.setTitle("请输入外出原因");
            final EditText et = new EditText(ZtActivity1.this);
            et.setSingleLine();
            et.setText(tv_fcyy.getText().toString());
            builder.setView(et);
            builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String sa = et.getText().toString().trim();
                    tv_fcyy.setText(sa+"");
                }

            });
            builder.show();
            Toast.makeText(this,"修改成功",Toast.LENGTH_SHORT).show();

        });

        tv_sj.setOnClickListener(v -> {

            AlertDialog.Builder builder = new AlertDialog.Builder(ZtActivity1.this);
            builder.setTitle("请输入申请时间");
            final EditText et = new EditText(ZtActivity1.this);
            et.setSingleLine();
            et.setText(sj+"");
            builder.setView(et);
            builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String sa = et.getText().toString().trim();
                    tv_sj.setText(sa+"");
                    tv_sj1.setText(sa+"");
                }

            });
            builder.show();
            Toast.makeText(this,"修改成功",Toast.LENGTH_SHORT).show();

        });

        tv_fdysj.setOnClickListener(v -> {

            AlertDialog.Builder builder = new AlertDialog.Builder(ZtActivity1.this);
            builder.setTitle("请输入辅导员审核时间，注意后面还有字");
            final EditText et = new EditText(ZtActivity1.this);
            et.setSingleLine();
            et.setText(tv_fdysj.getText().toString());
            builder.setView(et);
            builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String sa = et.getText().toString().trim();
                    tv_fdysj.setText(sa+"");
                }

            });
            builder.show();
            Toast.makeText(this,"修改成功",Toast.LENGTH_SHORT).show();


        });

        String name = intent.getStringExtra("name");
        String xueh = intent.getStringExtra("xuehao");

        String fdy1 = intent.getStringExtra("fdy");
        String xb1 = intent.getStringExtra("xb");
        String zy1 = intent.getStringExtra("zy");
        String bj1 = intent.getStringExtra("bj");
        String cxlx1 = intent.getStringExtra("cxlx");
        String lxfas1 = intent.getStringExtra("lxfs");
        String time = intent.getStringExtra("time");
        String fdyshsj = intent.getStringExtra("fdyshsj");

        tv_fdysj.setText(fdyshsj);

        tv_fxsj.setText(rq.format(new Date()) +"  "+ time);


        tv_fxsj.setOnClickListener(v -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(ZtActivity1.this);
            builder.setTitle("请输入返校时间");
            final EditText et = new EditText(ZtActivity1.this);
            et.setSingleLine();
            et.setText(rq.format(new Date()) +"  "+ time);
            builder.setView(et);
            builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String sa = et.getText().toString().trim();
                    tv_fxsj.setText(sa+"");
                }

            });
            builder.show();
            Toast.makeText(this,"修改成功",Toast.LENGTH_SHORT).show();

        });




        tv_fdy.setText(fdy1+"/"+xb1);
        tv_zhuanye.setText(zy1);
        tv_banji.setText(bj1);
        tv_cxlx.setText(cxlx1);
        tv_lxfas.setText(lxfas1);
        tv_xb.setText(xb1);

        tv_mz4.setText(name + "// ");
        tv_mz3.setText(name);
        tv_mz2.setText(name);
        tv_mz1.setText(name);

        tv_xueh.setText(xueh);

    }

    private void getqyt() {
        SimpleDateFormat f = new SimpleDateFormat("  yyyy-MM-                                                                                                                                                 dd ");
        SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd ");
        Date today = new Date();
        System.out.println("今天是:" + f.format(today));
        Calendar c = Calendar.getInstance();
        c.setTime(today);
        c.add(Calendar.DAY_OF_MONTH, -1);// 今天+1天

        Date tomorrow = c.getTime();

        int sj222 = random.nextInt(60);
        int sj23 = random.nextInt(60);
        tv_sj.setText(d.format(tomorrow) + " 08:" + sj222);
        sj = tv_sj.getText().toString();
        tv_sj1.setText(d.format(tomorrow) + " 08:" + sj222);
        tv_sj2.setText(d.format(tomorrow)  + " 08:" + (sj222-1));
        //    tv_fdysj.setText(f.format(tomorrow) + "  09:"+sj23);
    }


}